package com.zj.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zj.model.Reviews;
import com.zj.web.bean.ReviewsDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ReviewMapper extends BaseMapper<Reviews> {
    @Select("select r.*,u.userName,u.headUrl\n" +
            "from reviews r\n" +
            "left join user u on r.userId=u.userId\n" +
            "where r.productId=#{productId};")
    @Results({
            //property需要严格对照bean类的信息
            @Result(column = "reviewId", property = "reviewId"),
            @Result(column = "userId", property = "userId"),
            @Result(column = "productId", property = "productId"),
            @Result(column = "rating", property = "rating"),
            @Result(column = "comment", property = "comment"),
            @Result(column = "reviewImages", property = "reviewImages"),
            @Result(column = "createdAt", property = "createdAt"),
            @Result(column = "userName", property = "userName"),
            @Result(column = "headUrl", property = "headUrl"),
    })
    //根据商品ID查询评价列表
    List<ReviewsDTO> selectReviewsByProductId(Long productId);
    //根据商品ID和评分查询评价详情
    @Select("select r.*,u.userName,u.headUrl\n" +
            "from reviews r\n" +
            "left join user u on r.userId=u.userId\n" +
            "where r.productId=#{productId} and r.rating=#{rating};")
    @Results({
            //property需要严格对照bean类的信息
            @Result(column = "reviewId", property = "reviewId"),
            @Result(column = "userId", property = "userId"),
            @Result(column = "productId", property = "productId"),
            @Result(column = "rating", property = "rating"),
            @Result(column = "comment", property = "comment"),
            @Result(column = "reviewImages", property = "reviewImages"),
            @Result(column = "createdAt", property = "createdAt"),
            @Result(column = "userName", property = "userName"),
            @Result(column = "headUrl", property = "headUrl"),
    })
    List<ReviewsDTO> getReviewByIdAndRating(Long productId, Integer rating);
}
